package com.bnz.manager.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bnz.common.utils.PageUtils;
import com.bnz.common.utils.Query;

import com.bnz.manager.dao.GoodsDao;
import com.bnz.manager.entity.GoodsEntity;
import com.bnz.manager.service.GoodsService;


@Service("goodsService")
public class GoodsServiceImpl extends ServiceImpl<GoodsDao, GoodsEntity> implements GoodsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<GoodsEntity> page = this.page(
                new Query<GoodsEntity>().getPage(params),
                new QueryWrapper<GoodsEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * @author: zhanghao
     * @date: 2023/3/1 13:55
     * @param: [id, status]
     * @return: void
     * @功能: 商品审核
     **/
    @Override
    public void updateStatus(String id, String status) {
        this.update(new UpdateWrapper<GoodsEntity>().set(StringUtils.isNotBlank(status), "audit_status", status).eq("id", id));
        //2.2 方法二：
        // GoodsEntity entity = new GoodsEntity();
        // entity.setAuditStatus(status);
        // entity.setId(id);
        // this.updateById(entity);
    }

}